package com.chenfei.datasource.service.impl;

import com.chenfei.datasource.config.ReadOnlyConnection;
import com.chenfei.datasource.domain.Student;
import com.chenfei.datasource.mapper.StudentMapper;
import com.chenfei.datasource.service.DataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chenfei
 * @description
 * @since 2018/4/11
 */
@Service
public class DataSourceServiceImpl implements DataSourceService{

    @Autowired
    StudentMapper studentMapper;

    @Override
    public int addStudent() {
        Student student = new Student();
        student.setId(3);
        student.setAge(22);
        student.setName("test");
        return studentMapper.insertSelective(student);
    }

    @Override
    @ReadOnlyConnection
    public Student findStudent(Integer id) {
        return studentMapper.selectByPrimaryKey(id);
    }
}
